import java.util.Arrays;
import java.util.Scanner;

public class Main3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //以输入的n为参数构造ArrayIntegerStack
        ArrayIntegerStack arrayIntegerStack = new ArrayIntegerStack(Integer.parseInt(scanner.nextLine()));
        int m = Integer.parseInt(scanner.nextLine());
        //push并打印
        String string = scanner.nextLine();
        String[] strings = string.split(" ");
        int i = 0;
        while (m != i) {
            Integer integer = arrayIntegerStack.push(Integer.parseInt(strings[i]));
            System.out.println(integer);
            i++;
        }
        //栈顶 空 size elem[]
        System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
        System.out.println(Arrays.toString(arrayIntegerStack.elem));
        //pop并打印
        int x = Integer.parseInt(scanner.nextLine());
        while (x != 0) {
            System.out.println(arrayIntegerStack.pop());
            x--;
        }
        //栈顶 空 size elem[]
        System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
        System.out.println(Arrays.toString(arrayIntegerStack.elem));
    }
}

interface IntegerStack {
    Integer push(Integer item);    //如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。
    Integer pop();   //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
    Integer peek();   //获得栈顶元素，如果为空，则返回null.
    boolean empty();    //如果为空返回true
    public int size();    //返回栈中元素个数
}

class ArrayIntegerStack implements IntegerStack {

    Integer[] elem;
    int usedSize = 0;

    public ArrayIntegerStack(int n) {
        this.elem = new Integer[n];
    }

    @Override
    public Integer push(Integer item) {
        if (item == null) {
            return null;
        } else if (elem.length == usedSize) {
            return null;
        } else {
            elem[usedSize++] = item;
            return item;
        }
    }

    @Override
    public Integer pop() {
        if (usedSize == 0) {
            return null;
        } else {
            Integer integer = elem[usedSize - 1];
            usedSize--;
            return integer;
        }
    }

    @Override
    public Integer peek() {
        if (usedSize == 0) {
            return null;
        } else {
            return elem[usedSize - 1];
        }
    }

    @Override
    public boolean empty() {
        if (usedSize == 0) {
            return true;
        }
        return false;
    }

    @Override
    public int size() {
        return usedSize;
    }
}


